<!DOCTYPE html>
<html>

<head>
    <#include "/yq/admin/components/meta.html" />
    <title>蓁奕科技 ${metaTitleSuffix!}</title>
    <#include "/yq/admin/components/stylesheets.html" />
</head>

<body>
    <div id='app'>
        <el-container>
            <#assign menuIndex="1-3" />
            <#include "/yq/admin/components/menu.html" />
            <el-container>
                <#include "/yq/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-form ref="form" :model="form" label-width="80px">
                            <el-row>
                                <el-form-item label="商铺">
                                    <el-select v-model="form.shopId" placeholder="请选择" :disabled='${userRole!2} === 2'>
                                        <el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item label="标题">
                                    <el-input v-model="form.title"></el-input>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item label="封面">
                                    <el-upload class="avatar-uploader" :on-success="handleCoverSuccess" :on-error="handleCoverError" :http-request='uploadQnFile' list-type='picture' :show-file-list="false">
                                        <img v-if="form.cover" :src="form.cover" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item label="图片">
                                    <el-upload class="avatar-uploader" :on-success="handleImageSuccess" :on-error="handleImageError" :http-request='uploadQnFile' list-type='picture' :show-file-list="false">
                                        <img v-if="form.image" :src="form.image" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item label="状态">
                                    <el-radio-group v-model="form.status">
                                        <el-radio :label="1">正常</el-radio>
                                        <el-radio :label="0">禁用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item label="排序">
                                    <el-input v-model="form.sort" type="number"></el-input>
                                </el-form-item>
                            </el-row>
                            <el-row>
                                <el-form-item>
                                    <el-button type="primary" @click="onSubmit">保存</el-button>
                                </el-form-item>
                            </el-row>
                        </el-form>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/yq/admin/components/footer.html" />
    </div>
    <#include "/yq/admin/components/scripts.html" />
    <#include "/components/qiniu.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                form: ${info!'{}'},
                shops: toJson(`${shops!}`)
            }
        },
        mounted: function() {},
        methods: {
            onSubmit() {
                var param = {
                    id: this.form.id,
                    title: this.form.title,
                    status: this.form.status,
                    sort: this.form.sort,
                    cover: this.form.cover,
                    image: this.form.image,
                    shopId: this.form.shopId
                }
                // console.log(param)
                var url = ''
                var ref = '${referer!""}'
                var url = '/yq/admin/category/submit'
                axiosRequest(param, url, ref)
            },
            handleCoverSuccess(res, file) {
                console.log(res)
                console.log(file)
                this.form.cover = res.data.url
                console.log(this.form.cover);
                // this.form.cover = URL.createObjectURL(file.raw);
            },
            handleCoverError(err, file, fileList) {
                console.log(err);
            },
            handleImageSuccess(res, file) {
                console.log(res)
                console.log(file)
                this.form.image = res.data.url
                console.log(this.form.image);
                // this.form.cover = URL.createObjectURL(file.raw);
            },
            handleImageError(err, file, fileList) {
                console.log(err);
            }
        },
        filters: {
            fmt(date) {
                return date
            }
        }
    })
    </script>
    <style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    </style>
</body>

</html>